home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
ubppmpqs.zip
/
ppmp6.asm
< prev
next >
Wrap
Assembly Source File
|
1992-05-10
|
10KB
|
719 lines
;PPMP6.ASM 2.0
; MACHINE LANGUAGE SUBROUTINES
; FOR PPMPQS
; 1991/92 by YUJI KIDA
;
.386p
code segment use16
assume cs:code,ds:code
org 100h
start:
INCLUDE UBP.MAC
include ppmp.h
JMP start0
align 4
XMEMsize dd ?
ROWSbase dd ?
decompdatabase dd ?
decomppointerbase dd ?
historybase dd ?
freebase dd ?
totaloperations dd ?
P_OFF dw ?
P_SEG dw ?
E_OFF dw ?
E_SEG dw ?
Y_OFF dw ?
Y_SEG dw ?
DRV_OFF dw ?
DRV_SEG dw ?
primes dw ?
FBsize dw ?
Rmatrixsize dw ?
primehandle dw ?
ROWShandle dw ?
decomphandle dw ?
anshandle dw ?
histhandle dw ?
databuffer dw ?
ans_seg dw ?
Rbytes dw ?
Rwords dw ?
Tbytes dw ?
Twords dw ?
Tdwords dw ?
spmem dw ?
;branch
START0:
MOV_AX AR0 ;ARRAY[0] is the command number
MOV BX,OFFSET CMD_TBL
SHL AX,1
ADD BX,AX
JMP CS:[BX]
CMD_TBL:
DW final_init,square_ans,putPandE,closefiles
;
; close files
;
;command#=3
closefiles:
mov ah,3eh
mov bx,cs:[anshandle]
or bx,bx
jz short closefnext
int 21h
closefnext:
consefret:
retf
;
; answer exponents of p
;
;command#=2
putPandE:
mov ax,cs
mov ds,ax
mov es,ax
mov ebx,primeadr+12 ;exp part of 2
mov cx,[primes]
putPE10:
mov eax,fs:[ebx]
or eax,eax
jnz short putPE100
add ebx,8
loop putPE10
lds si,dword ptr [P_OFF]
mov word ptr [si],0 ;set 0 = no more data
putPEret:
mov ax,ss
mov ds,ax
mov es,ax
retf
putPE100:
mov dword ptr fs:[ebx],0 ;clear
lds si,dword ptr [E_OFF]
call seteax
mov eax,fs:[ebx-4]
lds si,dword ptr cs:[P_OFF]
call seteax
jmp putPEret
seteax:
mov cx,2
cmp eax,10000h
jae short seteaxjp
dec cx
or ax,ax
jnz short seteaxjp
dec cx
seteaxjp:
mov [si],cx
mov [si+2],eax
ret
;
; answer square data
;
;command#=1
square_ans:
mov ax,cs
mov ds,ax
mov es,ax
mov [spmem],sp
ans_again:
mov dx,offset BUFFER ;read answer
mov cx,[Rbytes]
mov bx,[anshandle]
mov ah,3fh
int 21h
or ax,ax
jz nomoreanswer
add ax,offset BUFFER
add ax,3
and ax,0fffch
mov [databuffer],ax
call translate
call backsubstitution
mov si,[databuffer]
mov cx,[Tbytes]
mov di,si
add di,cx
sub di,2 ;di = highest word adr
shr cx,1
xor ax,ax
std
repe scasw
cld
je ans_again ;illegal answer
inc cx ;word length
push es
mov es,[ans_seg]
xor di,di
mov ax,cx
stosw ;word length
rep movsw
pop es
call countexponents
squareret:
mov ax,ss
mov ds,ax
mov es,ax
retf
nomoreanswer:
mov bx,AR0
mov word ptr [bx],0
jmp squareret
translate:
mov di,[databuffer]
mov cx,[Tdwords]
xor eax,eax
rep stosd
mov ebx,[ROWSbase]
mov si,offset BUFFER
mov cx,[Rwords]
trans10:
push cx
lodsw
mov cx,16
trans20:
shr ax,1
jnc short trans30
push cx
push ax
mov di,fs:[ebx]
mov cx,di
and cl,7
shr di,3
mov al,1
shl al,cl
add di,[databuffer]
or [di],al
pop ax
pop cx
trans30:
add ebx,2
loop trans20
pop cx
loop trans10
ret
backsubstitution:
mov bx,[databuffer]
mov edx,[totaloperations]
mov esi,edx
dec esi
shl esi,2
add esi,[historybase]
align 4
backsubst10:
mov edi,fs:[esi]
mov cx,di
and cl,7
shr di,3
mov al,1
shl al,cl
test [di+bx],al
jnz short backsubst30
backsubst20:
sub esi,4
dec edx
jnz backsubst10
ret
align 4
backsubst30:
shr edi,16 ;source
mov cx,di
and cl,7
shr di,3
mov al,1
shl al,cl
xor [di+bx],al
jmp backsubst20
countexponents:
mov edi,primeadr+4 ;adr of exponents
mov cx,[FBsize]
xor eax,eax
ctexp10:
mov fs:[edi],eax ;clear exponents
add edi,8
loop ctexp10
mov ebx,[decomppointerbase]
mov si,[databuffer]
mov cx,[Twords]
ctexp20:
push cx
lodsw
mov cx,16
ctexp30:
shr ax,1
jc short ctexp100
ctexp40:
add ebx,4
loop ctexp30
pop cx
loop ctexp20
ret
ctexp100:
push ax
push cx
mov edi,fs:[ebx]
mov cx,fs:[edi]
align 4
ctexp110:
add edi,2
movzx eax,word ptr fs:[edi]
shl eax,3 ;*8
add eax,primeadr+4
inc dword ptr fs:[eax] ;inc exponents
loop ctexp110
pop cx
pop ax
jmp ctexp40
;
;* Initialize
;
;COMMAND#=0
;
final_init:
;get parameters
mov ax,cs
mov ds,ax
mov es,ax
mov [spmem],sp
MOV_AX V1+2 ;memo the segment of ans%(0)
ADD AX,ARRAYHEADSEG
MOV [ANS_SEG],AX
MOV BX,V2 ;memo the address of P
MOV AX,[BX]
MOV [P_OFF],AX
MOV AX,[BX+2]
MOV [P_SEG],AX
MOV BX,V3 ;memo the address of E
MOV AX,[BX]
MOV [E_OFF],AX
MOV AX,[BX+2]
MOV [E_SEG],AX
MOV BX,V4 ;memo the address of Y
MOV AX,[BX]
MOV [Y_OFF],AX
MOV AX,[BX+2]
MOV [Y_SEG],AX
MOV BX,V5 ;memo the address of DataDrv$
MOV AX,[BX]
MOV [DRV_OFF],AX
MOV AX,[BX+2]
MOV [DRV_SEG],AX
xor eax,eax
mov_ax AR1
shl eax,10
mov [XMEMsize],eax
mov_ax AR2
shl ax,1
mov [FBsize],ax
dec ax
mov [primes],ax
inc ax
shr ax,3 ;/ 8
mov [Tbytes],ax
shr ax,1
mov [Twords],ax
shr ax,1
mov [Tdwords],ax
call setPROTECTfs
call openANSFILE
call getPRIMES
call getROWS
call getDECOMPDATA
call gethistDATA
mov eax,[XMEMsize]
add eax,pmodeworkadr
cmp eax,[freebase]
jb short lackofmemory
initout:
mov ax,ss
mov ds,ax
mov es,ax
retf
diskerror:
mov ax,8001h
initerror:
mov ds:[AR0],ax
mov sp,[spmem]
jmp initout
lackofmemory:
mov ax,8002h
jmp initerror
openANSFILE:
mov dx,offset ansfilename ;read matrix size
mov ax,3d00h ;from answer file
int 21h
jc diskerror
mov [anshandle],ax
mov dx,offset Rmatrixsize ;get matrixsize
mov cx,2
mov bx,ax
mov ah,3fh ;read
int 21h
jc diskerror
mov ax,[Rmatrixsize]
shr ax,3
mov [Rbytes],ax
shr ax,1
mov [Rwords],ax
ret
gethistDATA:
mov ax,3d00h ;open for read
mov dx,offset historyfilename
int 21h
jc diskerror
mov [histhandle],ax
mov edi,[historybase]
gethist10:
mov dx,offset BUFFER
mov cx,400h
mov bx,[histhandle]
mov ah,3fh
int 21h
or ax,ax
jz short gethisteof
mov cx,ax
shr cx,2
mov si,offset BUFFER
gethist20:
lodsd
mov fs:[edi],eax
add edi,4
loop gethist20
jmp gethist10
gethisteof:
mov [freebase],edi
sub edi,[historybase]
shr edi,2 ;4bytes/unit
mov [totaloperations],edi
mov ah,3eh ;close file
mov bx,[histhandle]
int 21h
ret
getDECOMPDATA:
mov si,offset decompfilename
call setpathname
mov dx,offset BUFFER
mov ax,3d00h ;open for read
int 21h
jc diskerror
mov [decomphandle],ax
mov edi,[decompdatabase]
getdecomp10:
mov dx,offset BUFFER
mov cx,400h
mov bx,[decomphandle]
mov ah,3fh
int 21h
or ax,ax
jz short getdecompeof
mov cx,ax
shr cx,1
mov si,offset BUFFER
getdecomp20:
lodsw
mov fs:[edi],ax
add edi,2
loop getdecomp20
jmp getdecomp10
getdecompeof:
add edi,3
and di,0fffch
mov [decomppointerbase],edi
mov ah,3eh ;close file
mov bx,[decomphandle]
int 21h
mov ebx,[decomppointerbase]
mov eax,[decompdatabase]
xor edx,edx
getdecomp100:
mov fs:[ebx],eax
mov dx,fs:[eax]
inc dx
shl dx,1
add eax,edx
add ebx,4
cmp eax,[decomppointerbase]
jb getdecomp100
mov [historybase],ebx
ret
getROWS:
mov ax,3d00h ;open for read
mov dx,offset ROWSfilename
int 21h
jc diskerror
mov [ROWShandle],ax
mov edi,[ROWSbase]
getROWS10:
mov dx,offset BUFFER
mov cx,400h ;1024bytes unit
mov bx,[ROWShandle]
mov ah,3fh ;read
int 21h
or ax,ax
jz short getROWSeof
mov cx,ax
shr cx,1
mov si,offset BUFFER
getROWS20:
lodsw
mov fs:[edi],ax
add edi,2
loop getROWS20
jmp getROWS10
getROWSeof:
mov eax,edi
add eax,3
and ax,0fffch
mov [decompdatabase],eax
comment %
mov eax,edi
sub eax,[ROWSbase]
shr eax,1
mov [ROWSsize],ax
%
mov ah,3eh ;close file
mov bx,[ROWShandle]
int 21h
ret
getPRIMES:
mov si,offset primefilename
call setpathname
mov dx,offset BUFFER
mov ax,3d00h ;open for read
int 21h
jc diskerror
mov [primehandle],ax
mov edi,primeadr
primelp:
mov dx,offset BUFFER
mov cx,400h
mov bx,[pr